package com.easy.config;

import com.easy.interceptor.LoginInterceptor;
import com.easy.propertis.LoginInterceptorProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-04-23 14:44
 **/
@Configuration
public class LoginInterceptorAutoConfiguration implements WebMvcConfigurer {
    @Bean
    @ConfigurationProperties(prefix = "sso")
    public LoginInterceptorProperties configProperties() {
        return new LoginInterceptorProperties();
    }

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor()).addPathPatterns(configProperties().getWhitelist()).addPathPatterns(configProperties().getBlacklist());
    }
}
